<%- content_for :action_bar do %>
  <ol>
    <li class="action_bar-item">
      <%= link_to t(".actions.clean_expired_jwts"), clean_expired_jwts_account_jwts_path, method: :delete, remote: true %>
    </li>
  </ol>
<% end %>

<div class="row justify-content-center">
  <div class="col-lg-12">
    <h3 class="page-title">
      <%= t(".title") %>
    </h3>
    <%= form_tag account_jwts_path, class: 'form-inline' do -%>
      <div class="form-group">
        <label class="mr-1"><%= t(".form.aud") -%>：</label>
        <%= text_field_tag "aud", nil, class: 'form-control' %>
      </div>
      <div class="form-group">
        <label class="mr-1"><%= t(".form.exp_hours") -%>：</label>
        <%= text_field_tag "exp_hours", nil, class: 'form-control' %>
      </div>
      <div><%= submit_tag t(".actions.create"), class: 'btn btn-primary' %></div>
    <% end -%>
    <div class="table-responsive">
      <table class="table table-striped">
        <thead>
        <tr>
          <th><%= t(".table.user") %></th>
          <th><%= t(".table.jti") %></th>
          <th><%= t(".table.aud") %></th>
          <th><%= t(".table.exp") %></th>
          <th><%= t(".table.exp_relative") %></th>
          <th></th>
        </tr>
        </thead>
        <tbody>
        <% @whitelisted_jwts.each do |jwt| %>
          <tr>
            <td><%= jwt.user.email -%></td>
            <td>
              <% if jwt.exp <= Time.now %>
                <del><%= jwt.jti -%></del>
              <% else %>
                <%= jwt.jti -%>
              <% end %>
            </td>
            <td><%= jwt.aud -%></td>
            <td><%= jwt.exp.in_time_zone -%></td>
            <td>
              <% if jwt.exp <= Time.now %>
                <del><%= time_ago_in_words jwt.exp -%></del>
              <% else %>
                <%= time_ago_in_words jwt.exp -%>
              <% end %>
            </td>
            <td>
              <%= link_to t(".actions.delete"), account_jwt_path(jwt), method: :delete, data: { confirm: '你确定要删除吗？' } %>
            </td>
          </tr>
        <% end %>
        </tbody>
      </table>
    </div>
  </div>
</div>
